#include "gfxitem.h"
#include <QDebug>


GFXItem::GFXItem(ClientEntity *entity, QGraphicsItem *parent)
   : QGraphicsItem(parent),
     mEntity(entity),
     mActive(true),
     mTicksAlive(0),
     mShowRange(false),
     mPulsate(false),
     mPulsateScale(1.0),
     mPulsateCountUp(true),
     mUseEntity(true),
     mSquadSize(1)
{
   mCreateTime = QTime::currentTime();
}


GFXItem::GFXItem(const EntityBaseStats &stats, QGraphicsItem *parent)
   : QGraphicsItem(parent),
     mEntity(0),
     mActive(true),
     mTicksAlive(0),
     mShowRange(false),
     mPulsate(false),
     mPulsateScale(1.0),
     mPulsateCountUp(true),
     mStats(stats),
     mUseEntity(false),
     mSquadSize(1)
{
   mCreateTime = QTime::currentTime();
}


GFXItem::~GFXItem()
{
}


void GFXItem::tick()
{
   if (mPulsate)
   {
      // Fun little pulse animation for selections, etc
      mPulsateScale += (mPulsateCountUp) ? 0.020 : -0.020;

      if (mPulsateScale >= 1.15)
         mPulsateCountUp = false;
      else if (mPulsateScale <= 1.0)
         mPulsateCountUp = true;
      // ...Now just set the painter scale to mPulsateScale in paint()
      // Calling setScale here pulsates tower ranges, which we don't
      // really want...
      update(); // needed here otherwise cursor item pulsates only when moved.
   }
}


QVariant GFXItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
    if (change == ItemSelectedHasChanged)
       mPulsate=isSelected();
    return QGraphicsItem::itemChange(change, value);
}

void GFXItem::setShowRange(bool show) { mShowRange = show; }
void GFXItem::setBlendRange(bool value) { mBlendRange = value; }
void GFXItem::setPulsate(bool pulsate) { mPulsate = pulsate; }
ClientEntity*  GFXItem::entity() { return mEntity; }
void GFXItem::setEntity(ClientEntity *entity) { mEntity = entity; }
bool GFXItem::active() { return mActive; }
void GFXItem::setActive(const bool active) { mActive = active; }
void GFXItem::setSquadSize(const qint32 value) { mSquadSize = value; }
qint32 GFXItem::squadSize() { return mSquadSize; }
EntityBaseStats GFXItem::stats() { return mStats; }
